﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="RunRepositoryMock.cs" company="melcoprog">
//   Copyright (c) melcoprog. All rights reserved.
// </copyright>
// <summary>
//   Defines the RunRepositoryMock type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace CreatureSheep.CreatureStates
{
    using System.Collections.Generic;
    using System.Drawing;
    using System.Drawing.Drawing2D;

    using CreatureSheep.Image;

    using ESheep;

    /// <summary>
    /// The run repository mock.
    /// </summary>
    public class RunRepository : IStateRepository
    {
        /// <summary>
        /// The image.
        /// </summary>
        private readonly Bitmap image;

        /// <summary>
        /// Initializes a new instance of the <see cref="RunRepository"/> class.
        /// </summary>
        /// <param name="image">
        /// The image.
        /// </param>
        public RunRepository(Bitmap image)
        {
            this.image = image;
        }

        /// <summary>
        /// The get configuration.
        /// </summary>
        /// <returns>
        /// The <see cref="StateConfiguration"/>.
        /// </returns>
        public StateConfiguration GetConfiguration()
        {
            const int Height = 40;
            const int Width = 40;

            var idleConfiguration = new StateConfiguration
            {
                Height = Height,
                Width = Width,
                LeftSprites = new List<KeyValuePair<Bitmap, GraphicsPath>>(),
                RightSprites = new List<KeyValuePair<Bitmap, GraphicsPath>>()
            };

            var sprites = new SpriteMaker(this.image, Width, Height);

            var sprite1 = sprites.GetSprite(4, 1);
            var path1 = BitmapRegion.CalculateControlGraphicsPath(sprite1);

            idleConfiguration.LeftSprites.Add(new KeyValuePair<Bitmap, GraphicsPath>(sprite1, path1));

            var sprite2 = sprites.GetSprite(5, 1);
            var path2 = BitmapRegion.CalculateControlGraphicsPath(sprite2);

            idleConfiguration.LeftSprites.Add(new KeyValuePair<Bitmap, GraphicsPath>(sprite2, path2));

            foreach (var sprite in idleConfiguration.LeftSprites)
            {
                var bmp = (Bitmap)sprite.Key.Clone();
                bmp.RotateFlip(RotateFlipType.RotateNoneFlipX);
                var path = BitmapRegion.CalculateControlGraphicsPath(bmp);
                idleConfiguration.RightSprites.Add(new KeyValuePair<Bitmap, GraphicsPath>(bmp, path));
            }

            return idleConfiguration;
        }
    }
}
